home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / workbench / fullbench-3.00 / old / fullbench-1.21 / src / fullbench.c next >
C/C++ Source or Header  |  2000-02-28  |  5KB  |  171 lines

  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include <proto/intuition.h>
  4. #include <proto/exec.h>
  5. #include <exec/ports.h>
  6. #include <dos/dos.h>
  7. #include <proto/dos.h>
  8. #include <dos/notify.h>
  9. #include <exec/memory.h>
  10.  
  11. static UBYTE *version_string = "$VER: FullBench 1.21 (2.10.95)";
  12.  
  13. BOOL InitFull(struct Window **MyWindow, BOOL);
  14.  
  15. __chip UWORD knapp[] =
  16. {
  17.   0x0000,0x0000,0x0000,0x0200,0x0FFC,0x0200,0x0800,0x0200,
  18.   0x0800,0x0200,0x0800,0x2200,0x0800,0x2200,0x0800,0x2200,
  19.   0x0000,0x2200,0x0000,0x2200,0x007F,0xE200,0x0000,0x0200,
  20.   0xFFFF,0xFE00,
  21.  
  22.   0xFFFF,0xFE00,0x8000,0x0000,0x8000,0x0000,0x8002,0x0000,
  23.   0x80FF,0xC000,0x8080,0x0000,0x8080,0x0000,0x8080,0x0000,
  24.   0x8780,0x0000,0x8080,0x0000,0x8000,0x0000,0x8000,0x0000,
  25.   0x0000,0x0000,
  26. };
  27. __chip UWORD knapp2[] =
  28. {
  29.   0xFFFF,0xFE00,0x8000,0x0000,0x8000,0x0000,0x8002,0x0000,
  30.   0x8002,0x0000,0x8002,0x2000,0x8002,0x2000,0x8002,0x2000,
  31.   0x87FE,0x2000,0x8000,0x2000,0x807F,0xE000,0x8000,0x0000,
  32.   0x0000,0x0000,
  33.  
  34.   0x0000,0x0000,0x0000,0x0200,0x0FFC,0x0200,0x0800,0x0200,
  35.   0x08FD,0xC200,0x0880,0x0200,0x0880,0x0200,0x0880,0x0200,
  36.   0x0000,0x0200,0x0080,0x0200,0x0000,0x0200,0x0000,0x0200,
  37.   0xFFFF,0xFE00,
  38. };
  39.  
  40. struct Image MyButt =
  41. {
  42.   0, 0,            /* Upper left corner */
  43.   23, 13, 2,        /* Width, Height, Depth */
  44.   knapp,        /* Image data */
  45.   0x03, 0x00,    /* PlanePick, PlaneOnOff */
  46.   NULL,            /* Next image */
  47. };
  48. struct Image MyButt2 =
  49. {
  50.   0, 0,            /* Upper left corner */
  51.   23, 13, 2,        /* Width, Height, Depth */
  52.   knapp2,        /* Image data */
  53.   0x03, 0x00,    /* PlanePick, PlaneOnOff */
  54.   NULL,            /* Next image */
  55. };
  56.  
  57. struct EasyStruct err = {
  58.   sizeof(struct EasyStruct), 0,
  59.   "FullBench 1.21", 
  60.   "Can't find Worbench screen\n  or WB is not backdrop",
  61.   "Continue",
  62. };
  63.  
  64. struct Gadget MyDepthGad = {
  65.   NULL, 0, 0, 24, 13,
  66.   GFLG_GADGIMAGE | GFLG_GADGHIMAGE,
  67.   GACT_RELVERIFY,
  68.   GTYP_SDEPTH,
  69.   &MyButt, &MyButt2, NULL, NULL, NULL
  70. };
  71.  
  72. void __stdargs __main(char *unused)
  73. {
  74.   struct Window *MyWindow=NULL;
  75.   struct Task *OldTask;
  76.   int signal, signr=-1;
  77.   struct NotifyRequest *MyNotify;
  78.   BOOL notify = FALSE;
  79.   STRPTR oldname = FindTask(NULL)->tc_Node.ln_Name;
  80.   
  81.   Forbid();
  82.   if(OldTask = FindTask("task_FullBench"))
  83.     {
  84.       Signal(OldTask, SIGBREAKF_CTRL_C);
  85.       Permit();
  86.       exit(0);
  87.     }
  88.   Permit();
  89.   
  90.   FindTask(NULL)->tc_Node.ln_Name = "task_FullBench";
  91.  
  92.   if((MyNotify = AllocMem(sizeof(struct NotifyRequest), MEMF_CLEAR))
  93.      && (signr = AllocSignal(-1L)) != -1){
  94.     MyNotify->nr_Name = "Env:sys/screenmode.prefs";
  95.     MyNotify->nr_Flags = NRF_SEND_SIGNAL;
  96.     MyNotify->nr_stuff.nr_Signal.nr_Task = (struct Task *) FindTask(NULL);
  97.     MyNotify->nr_stuff.nr_Signal.nr_SignalNum = signr;
  98.     StartNotify(MyNotify);
  99.     notify = TRUE;
  100.   }
  101.   
  102.   if(!InitFull(&MyWindow, TRUE)) goto quit;
  103.   for(;;){
  104.     signal = Wait(SIGBREAKF_CTRL_C | (1L << signr));
  105.     if(!(signal & (1L << signr))) break;
  106.     if(MyWindow){
  107.       CloseWindow(MyWindow);
  108.       MyWindow = NULL;
  109.     }
  110.     Delay(250);
  111.     if(!InitFull(&MyWindow, TRUE)) goto quit;
  112.   }
  113.   InitFull(&MyWindow, FALSE);  
  114.   
  115.  quit:
  116.   FindTask(NULL)->tc_Node.ln_Name = oldname;
  117.   if(notify) EndNotify(MyNotify);
  118.   if(signr != -1) FreeSignal(signr);
  119.   if(MyNotify) FreeMem(MyNotify, sizeof(struct NotifyRequest));
  120.   if(MyWindow) CloseWindow(MyWindow);
  121.   exit (0);
  122. }
  123.  
  124.  
  125. BOOL InitFull(struct Window **MyWindow, BOOL on)
  126. {
  127.   struct Window *WBWin;
  128.   BOOL error = FALSE;
  129.   struct Screen *WBScreen;
  130.   
  131.   if((!(WBScreen = (struct Screen *)LockPubScreen("Workbench")))){
  132.     EasyRequestArgs(NULL, &err, NULL, NULL);
  133.     return(FALSE);
  134.   }
  135.   Forbid();
  136.   for(WBWin = WBScreen->FirstWindow; WBWin
  137.       && (strncmp(WBWin->ScreenTitle,"Amiga Workbench",15)
  138.       && strncmp(WBWin->ScreenTitle,"Attempting to load program",25)
  139.       && strncmp(WBWin->ScreenTitle,"Copyright © 1985-199",20)
  140.       && strncmp(WBWin->ScreenTitle,"Cannot Quit yet",15)
  141.       || WBWin->Title!=NULL); WBWin = WBWin->NextWindow);
  142.   Permit();
  143.   if (!WBWin) {
  144.     EasyRequestArgs(NULL, &err, NULL, NULL);
  145.     goto quit;
  146.   }
  147.   if(on) 
  148.     ChangeWindowBox(WBWin,WBWin->LeftEdge,0, WBWin->Width,WBScreen->Height);
  149.   else
  150.     ChangeWindowBox(WBWin,WBWin->LeftEdge,(WBScreen->BarHeight+1),
  151.             WBWin->Width,WBScreen->Height-(WBScreen->BarHeight+1));
  152.   
  153.   ShowTitle(WBScreen, !on); /* Vises kun ved full workbench */
  154.   
  155.   if(on){
  156.     if(!((*MyWindow) = OpenWindowTags(NULL, WA_Top, 0,
  157.                       WA_Left, 32000,
  158.                       WA_Height, MyButt.Height,
  159.                       WA_Width, MyButt.Width,
  160.                       WA_AutoAdjust, TRUE,
  161.                       WA_Gadgets, &MyDepthGad,
  162.                       WA_Flags, WFLG_BORDERLESS|WFLG_BACKDROP,
  163.                       TAG_END)))
  164.       goto quit;
  165.     error=TRUE;
  166.   }
  167.  quit:
  168.   UnlockPubScreen(NULL, WBScreen);
  169.   return(error);
  170. }
  171.